package view;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import controller.Sistema;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class RegistrarConsumoPorLinea extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private RegistrarConsumoPorLinea instancia;
	private JLabel IDServicio;
	private JButton Cancelar;
	private JButton Aceptar;
	private JTextField NumeroLinea1;
	private JLabel NumeroLinea;
	private JTextField CantidadConsumos1;
	private JLabel CantidadConsumos;
	private JTextField Pagado1;
	private JLabel Pagado;
	private JTextField IDServicio1;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				RegistrarConsumoPorLinea inst = new RegistrarConsumoPorLinea();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public RegistrarConsumoPorLinea() {
		super();
		initGUI();
		instancia= this;
		{
			IDServicio = new JLabel();
			getContentPane().add(IDServicio);
			IDServicio.setText("ID Servicio");
			IDServicio.setBounds(37, 25, 116, 16);
		}
		{
			IDServicio1 = new JTextField();
			getContentPane().add(IDServicio1);
			IDServicio1.setBounds(187, 22, 167, 23);
		}
		{
			Pagado = new JLabel();
			getContentPane().add(Pagado);
			Pagado.setText("Pagado");
			Pagado.setBounds(37, 70, 116, 16);
		}
		{
			Pagado1 = new JTextField();
			getContentPane().add(Pagado1);
			Pagado1.setBounds(187, 67, 167, 23);
		}
		{
			CantidadConsumos = new JLabel();
			getContentPane().add(CantidadConsumos);
			CantidadConsumos.setText("Cantidad Consumos");
			CantidadConsumos.setBounds(37, 117, 138, 16);
		}
		{
			CantidadConsumos1 = new JTextField();
			getContentPane().add(CantidadConsumos1);
			CantidadConsumos1.setBounds(187, 114, 167, 23);
		}
		{
			NumeroLinea = new JLabel();
			getContentPane().add(NumeroLinea);
			NumeroLinea.setText("Numero Linea");
			NumeroLinea.setBounds(37, 160, 138, 16);
		}
		{
			NumeroLinea1 = new JTextField();
			getContentPane().add(NumeroLinea1);
			NumeroLinea1.setBounds(187, 157, 167, 23);
		}
		{
			Aceptar = new JButton();
			getContentPane().add(Aceptar);
			Aceptar.setText("Aceptar");
			Aceptar.setBounds(79, 210, 84, 27);
			Aceptar.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					try {
						Sistema.getInstance().registrarConsumo(Integer.parseInt(NumeroLinea1.getText()), IDServicio1.getText(), Float.parseFloat(CantidadConsumos1.getText()));
					} catch (NumberFormatException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					limpiarCampos();
					
				}
			});
		}
		{
			Cancelar = new JButton();
			getContentPane().add(Cancelar);
			Cancelar.setText("Cancelar");
			Cancelar.setBounds(203, 211, 89, 25);
			Cancelar.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					Menu app = new Menu();
					app.setLocationRelativeTo(null);
					app.setVisible(true);
					instancia.dispose();
					
				}
			});
			
		}
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			pack();
			setSize(400, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private void limpiarCampos() {
		IDServicio1.setText("");
		Pagado1.setText("");
		CantidadConsumos1.setText("");
		NumeroLinea1.setText("");

		
	}

}
